package com.one.apartmentsystem.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.one.apartmentsystem.app.domain.ContractInfo;
import com.one.apartmentsystem.app.domain.HousesInfo;
import com.one.apartmentsystem.app.domain.RentalInfo;
import com.one.apartmentsystem.app.mapper.ContractInfoMapper;
import com.one.apartmentsystem.app.mapper.HousesInfoMapper;
import com.one.apartmentsystem.app.service.RentalInfoService;
import com.one.apartmentsystem.app.mapper.RentalInfoMapper;
import com.one.apartmentsystem.app.vo.HouseDetailsVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @author mpk16
* @description 针对表【rental_info(提交记录表 每30天清空)】的数据库操作Service实现
* @createDate 2024-08-03 13:39:49
*/
@Service
public class RentalInfoServiceImpl extends ServiceImpl<RentalInfoMapper, RentalInfo>
    implements RentalInfoService{

    @Autowired
    private RentalInfoMapper rentalInfoMapper;
    @Autowired
    HousesInfoMapper housesInfoMapper;
    @Autowired
    ContractInfoMapper contractInfoMapper;

    @Override
    public List<HouseDetailsVO> getSingUp(String userId) {

        HashMap<String, Object> map = new HashMap<>();
        map.put("use_id",userId);
        List<ContractInfo> contractInfos = contractInfoMapper.selectByMap(map);
        List<HouseDetailsVO> houseDetailsVOS = new ArrayList<>();
        contractInfos.forEach(
                rentalInfo -> {
                    HouseDetailsVO houseDetailsVO = new HouseDetailsVO();
                    HousesInfo housesInfo = housesInfoMapper.selectById(rentalInfo.getHouseId());
                    BeanUtils.copyProperties(housesInfo,houseDetailsVO);
                    houseDetailsVOS.add(houseDetailsVO);
                }
        );
        return houseDetailsVOS;
    }
}




